Augment Golo in Golo
1. Create a new Golo module
In /stdlib, create a new file named (for example) k33g.golo with the following content:
module gololang.K33g
function HelloWorld = -> "👋 Hello World 🌍"
function Greet = |name| -> "👋 Hello, " + name + "! 😁"
function ShoutGreet = |name| ->
"📣 " +
Greet(name): toUpperCase() +
"!!!"
The name of the module must start with
gololang.to be recognized as a standard library module.
2. Update stdlib/stdlib.go
In the stdlib/stdlib.go file,
first, define a new variable for your module:
//go:embed k33g.golo
var k33gSource string
With
go:embed, you can embed the content of your Golo file (k33g.golo) directly into the Go binary.
Then, add your module to the EmbeddedModules map:
var EmbeddedModules = map[string]string{
"gololang.Errors": errorsSource,
"gololang.K33g": k33gSource,
"gololang.AnsiCodes": ansicodesSource,
"gololang.Testing": testingSource,
}
3. Rebuild the Golo binary
go build
4. Use your new module in Golo
main.golo:
module demo.main
import gololang.K33g
function main = |args| {
println(HelloWorld())
println(Greet("K33g"))
println(ShoutGreet("K33g"))
}
Then, run:
golo main.golo
The output should be:
👋 Hello World 🌍
👋 Hello, K33g! 😁
📣 👋 HELLO, K33G! 😁!!!